<template>
	<view>
		
		<view class="flex whiteBg plr bb">
			<view>
				<view class="ptb10" v-if="page.list.length > 0" >
					<range-picker @change="changeDate"></range-picker>
				</view>
			</view>
			<staffAuth>
				<navigator hover-class="op9" :url="`/pages/saveRuns/saveRuns?id=${sid}&realType=${realType}`">
					<view class=" ptb10 flex left">
						<text class="pr5 fz16 sIcon-addCircle bold main"></text>
						<view>
							添加记录
						</view>
					</view>
				</navigator>
			</staffAuth>
		</view>
		
		<view class="">
			<view class=" whiteBg" v-for="( sitem , sindex) in page.list" :key="sindex">
				
				<collapser :title="sitem.type">
					
					<view>
						{{sitem.createTime}}
					</view>
					
					<template slot="content">
						
						<upload-img max="20" title="运维照片" :value="sitem.pics" :disabled="true"></upload-img>
						
						<view class="pd ptb10">
							
							<view class="flex">
								<view>
									<text class="grey mr5">时间</text>
								</view>
								<view>
									{{sitem.startTime}} ~ {{sitem.endTime}}
								</view>
							</view>
							
							<view class="flex pt5">
								<view>
									<text class="grey mr5">运维公司</text>
								</view>
								<view>
									{{sitem.servicerName}}
								</view>
							</view>
							
							<view class="flex pt5">
								<view>
									<text class="grey mr5">记录人</text>
								</view>
								<view>
									{{sitem.recorder}}
								</view>
							</view>
						</view>
						
					</template>
					
				</collapser>
				
			</view>
		</view>
		
		<empty :loading="loading" :list="page.list"></empty>
		
		
	</view>
</template>

<script>
	export default {
		name:"run-records",
		props:{
			sid : [String,Number],
			realType : {
				type : Number ,
				default : 1
			}
		},
		data() {
			return {
				refresh : false ,
				page : {
					list : [] ,
					lastPage : false ,
					pageNumber : 1 ,
					pageSize : 10
				},
				loading : true ,
				startTime : "" ,
				endTime : ""
			};
		},
		
		created() {
			this.page.pageNumber = 1 ;
			this.loading = true ;
			this.loadData();
		},
		
		methods:{
			
			changeDate : function(e){
				this.startTime = e.startDate ;
				this.endTime = e.endDate ;
				this.refreshing();
			},

			getMore() {
				if (this.page.lastPage) {
					return ;
				}
				this.page.pageNumber ++ ;
				this.loadData();
			},
			
			refreshing(){
				if (this.refresh) {
					return ;
				}
				this.refresh = true ;
				this.page.pageNumber = 1 ;
				this.loadData();
			},
			
			loadData:function(e){
				var data = {
					pageNumber : this.page.pageNumber ,
					pageSize : this.page.pageSize ,
					"trr.createTime.start" : this.startTime ,
					"trr.createTime.end" : this.endTime ,
					"trr.stationId" : this.sid ,
					"trr.realType" : this.realType 
				} ;
				this.kit.get("/api/runRecords/list",data,res => {
					if (res.page.pageNumber > 1) {
						res.page.list = this.page.list.concat(res.page.list);
					}
					this.page = res.page ;
					this.loading = false ;
					this.refresh = false ;
				});
			}
		}
	}
</script>
